package notused;

import java.sql.CallableStatement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class StoredProcedureExample {

	static String connectionString = "jdbc:mysql://localhost/cdr_db?"
			+ "user=root&password=";

	public static void main(String[] args) {
		StoredProcedureExample app = new StoredProcedureExample();
//		app.test1();
		app.test2();

	}

	java.sql.Connection connect;

	public StoredProcedureExample() {
		connect = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			connect = DriverManager.getConnection(connectionString);
		} catch (Exception e) {
			System.err
					.println("Error while establishing connection with connection string "
							+ connectionString);
			e.printStackTrace();
			try {
				connect.close();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} finally {
		}
	}

	public void test1() {
		String testProc = "{ call testproc() }";
		try {
			CallableStatement cs = connect.prepareCall(testProc);
			cs.executeQuery();
			ResultSet rs = cs.getResultSet();
			rs.next();
			System.out.println(rs.getInt(1));
//			boolean b = cs.getMoreResults();
			rs = cs.getResultSet();
			rs.next();
			System.out.println(rs.getInt(1));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void test2() {
		String testProc = "{ call testproc2(?) }";
		try {
			CallableStatement cs = connect.prepareCall(testProc);
			cs.setString(1, "03775:06926425");
			cs.executeQuery();
			ResultSet rs = cs.getResultSet();
			rs.next();
			System.out.println(rs.getInt(1));
			boolean b = cs.getMoreResults();
			rs = cs.getResultSet();
			rs.next();
			System.out.println(rs.getInt(1));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
